package com.baizhi.springbootshiro.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.common.collect.Maps;
import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;
import java.util.Map;

@Data
public class R implements Serializable {

    private Integer code;
    private String message;

    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private Map<String, Object> data = Maps.newHashMap();

    public R() {

    }

    public static R ok() {
        R r = new R();
        r.setCode(HttpStatus.OK.value());
        r.setMessage(HttpStatus.OK.getReasonPhrase());
        return r;
    }

    public static R error() {
        R r = new R();
        r.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        r.setMessage(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
        return r;
    }

    public R data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    public R data(Map<String, Object> data) {
        this.data = data;
        return this;
    }


}
